package com.rs2lite.loader;

import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.net.URL;
import java.net.URLClassLoader;

import com.rs2lite.RS2Lite;

/**
 * Class GameAppletLoader, loads the runescape applet.
 * 
 * @author Nicole <nicole@rune-server.org> This file is protected by The BSD
 *         License, You should have recieved a copy named "BSD License.txt"
 */

public class GameAppletLoader implements AppletStub {

	private Applet app;

	private RS2Lite parent;

	public GameAppletLoader(RS2Lite parent) {
		this.parent = parent;
		try {
			URLClassLoader localURLClassLoader = new URLClassLoader(
					new URL[] { new URL(RS2Lite.parseClientLoader()) });
			app = (Applet) localURLClassLoader.loadClass("loader")
					.newInstance();
			app.setStub(this);
			app.setVisible(true);
			app.init();
			app.start();
		} catch (Exception localException) {
			localException.printStackTrace();
		}
	}

	public Applet getApplet() {
		return app;
	}

	@Override
	public boolean isActive() {
		return app.isActive();
	}

	@Override
	public void appletResize(int arg0, int arg1) {

	}

	@Override
	public AppletContext getAppletContext() {
		return null;
	}

	@Override
	public URL getDocumentBase() {
		return getCodeBase();
	}

	@Override
	public URL getCodeBase() {
		try {
			return new URL(RS2Lite.url);
		} catch (Exception ex) {
			return null;
		}
	}

	@Override
	public String getParameter(String req) {
		return parent.props.get(req);
	}
}